package com.example.business_oa.controller;

import com.example.business_oa.service.FuLiZhuBiaoService;
import com.example.business_oa.service.JuJueFuLiLiuChengService;
import com.example.business_oa.service.SelectLeaderService;
import com.example.comment_oa.pojos.FlApplyzhu;
import com.example.comment_oa.pojos.SysEmployee;
import com.example.comment_oa.pojos_vo.flowableVo.taskVo;
import com.example.comment_oa.pojos_vo.salaryVo.LingDaoVo;
import com.example.comment_oa.response.AjaxResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping("/businessOa")
public class FuLiLiuChengWanChengController {
    @Resource
    FuLiZhuBiaoService fuLiZhuBiaoService;

    @Resource
    JuJueFuLiLiuChengService juJueFuLiLiuChengService;

    @Resource
    SelectLeaderService selectLeaderService;


    @PostMapping("/jujue")
    public AjaxResponse juejueliucehng(@RequestBody taskVo taskVo){

        // 拿到流程发起人是谁
        String person = taskVo.getPerson();
        SysEmployee sysEmployee = selectLeaderService.selectEmailZiji(person);
        // 然后把他的邮箱存进去
        taskVo.setPersongemail(sysEmployee.getEmpEmail());
        // 拿到领导是谁
        String lingdao = taskVo.getLingdao();
        SysEmployee sysEmployee1 = selectLeaderService.selectEmailZiji(lingdao);
        LingDaoVo lingDaoVo = new LingDaoVo();
        lingDaoVo.setLingdaobumen(sysEmployee1.getDept().getDeptName());
        lingDaoVo.setLingdaogonghao(sysEmployee1.getEmpCard());
        lingDaoVo.setLingdaoname(sysEmployee1.getEmpName());
        lingDaoVo.setLingdaozhiwu(sysEmployee1.getEmployeePost().getPost().getPostName());
        lingDaoVo.setLiuchengbianhao(taskVo.getBianhao());
        fuLiZhuBiaoService.shenpijujue(lingDaoVo);

        juJueFuLiLiuChengService.jujuefuliliucheng(taskVo);
        return AjaxResponse.success();
    }


    @PostMapping("/tongyi")
    public AjaxResponse tongyiliucehng(@RequestBody taskVo taskVo){

        // 拿到流程发起人是谁
        String person = taskVo.getPerson();
        SysEmployee sysEmployee = selectLeaderService.selectEmailZiji(person);
        // 然后把他的邮箱存进去
        taskVo.setPersongemail(sysEmployee.getEmpEmail());

        FlApplyzhu chazhubiao = fuLiZhuBiaoService.chazhubiao(taskVo.getBianhao());
        if (chazhubiao.getFlFlowablestatus()==2){
            juJueFuLiLiuChengService.tongyifuliliucheng(taskVo);
        }else {

            // 拿到领导是谁
            String lingdao = taskVo.getLingdao();
            SysEmployee sysEmployee1 = selectLeaderService.selectEmailZiji(lingdao);
            LingDaoVo lingDaoVo = new LingDaoVo();
            lingDaoVo.setLingdaobumen(sysEmployee1.getDept().getDeptName());
            lingDaoVo.setLingdaogonghao(sysEmployee1.getEmpCard());
            lingDaoVo.setLingdaoname(sysEmployee1.getEmpName());
            lingDaoVo.setLingdaozhiwu(sysEmployee1.getEmployeePost().getPost().getPostName());
            lingDaoVo.setLiuchengbianhao(taskVo.getBianhao());
            fuLiZhuBiaoService.shenpitongyi(lingDaoVo);

            juJueFuLiLiuChengService.tongyifuliliucheng(taskVo);
        }
        return AjaxResponse.success();
    }


}
